package com.kaifamiao.list;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

public class ListIteratorTest2 {

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.addAll( List.of("孙悟空","猪悟能","沙悟净","熊大","熊二","光头强") );
        System.out.println( list );

        ListIterator<String> itor = list.listIterator();

        while( itor.hasNext() ){
            String name = itor.next();
            if( "光头强".equals( name ) ) {
                itor.remove();
                itor.add( "翠花" );
            }
            if( "猪悟能".equals( name ) ){
                itor.set( "天蓬元帅" );
            }
        }

        System.out.println( list );


    }

}
